home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / ipc / util.c < prev   
Encoding:
C/C++ Source or Header  |  1994-06-05  |  3.5 KB  |  157 lines

  1. /*
  2.  * linux/ipc/util.c
  3.  * Copyright (C) 1992 Krishna Balasubramanian
  4.  */
  5.  
  6. #include <linux/config.h>
  7. #include <linux/errno.h>
  8. #include <asm/segment.h>
  9. #include <linux/sched.h>
  10. #include <linux/sem.h>
  11. #include <linux/msg.h>
  12. #include <linux/shm.h>
  13. #include <linux/stat.h>
  14.  
  15. void ipc_init (void);
  16. asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr); 
  17.  
  18. #ifdef CONFIG_SYSVIPC
  19.  
  20. int ipcperms (struct ipc_perm *ipcp, short flag);
  21. extern void sem_init (void), msg_init (void), shm_init (void);
  22. extern int sys_semget (key_t key, int nsems, int semflg);
  23. extern int sys_semop (int semid, struct sembuf *sops, unsigned nsops);
  24. extern int sys_semctl (int semid, int semnum, int cmd, void *arg);
  25. extern int sys_msgget (key_t key, int msgflg);
  26. extern int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg);
  27. extern int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
  28.                int msgflg);
  29. extern int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf);
  30. extern int sys_shmctl (int shmid, int cmd, struct shmid_ds *buf);
  31. extern int sys_shmget (key_t key, int size, int flag);
  32. extern int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *addr);
  33. extern int sys_shmdt (char *shmaddr);
  34.  
  35. void ipc_init (void)
  36. {
  37.     sem_init();
  38.     msg_init();
  39.     shm_init();
  40.     return;
  41. }
  42.  
  43. /* 
  44.  * Check user, group, other permissions for access
  45.  * to ipc resources. return 0 if allowed
  46.  */
  47. int ipcperms (struct ipc_perm *ipcp, short flag)
  48. {
  49.     int i; mode_t perm; uid_t euid; int egid;
  50.     
  51.     if (suser())
  52.         return 0;
  53.  
  54.     perm = S_IRWXO; euid = current->euid;
  55.  
  56.     if (euid == ipcp->cuid || euid == ipcp->uid) 
  57.         perm = S_IRWXU;
  58.     else {
  59.         for (i = 0; (egid = current->groups[i]) != NOGROUP; i++)
  60.             if ((egid == ipcp->cgid) || (egid == ipcp->gid)) { 
  61.                 perm = S_IRWXG; 
  62.                 break;
  63.             }
  64.     }
  65.     if (!(flag & perm) || flag & perm & ~ipcp->mode)
  66.         return -1;
  67.     return 0;
  68. }
  69.  
  70. asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
  71. {
  72.     
  73.     if (call <= SEMCTL)
  74.         switch (call) {
  75.         case SEMOP:
  76.             return sys_semop (first, (struct sembuf *)ptr, second);
  77.         case SEMGET:
  78.             return sys_semget (first, second, third);
  79.         case SEMCTL:
  80.             return sys_semctl (first, second, third, ptr);
  81.         default:
  82.             return -EINVAL;
  83.         }
  84.     if (call <= MSGCTL) 
  85.         switch (call) {
  86.         case MSGSND:
  87.             return sys_msgsnd (first, (struct msgbuf *) ptr, 
  88.                        second, third);
  89.         case MSGRCV: {
  90.             struct ipc_kludge tmp; 
  91.             if (!ptr)
  92.                 return -EINVAL;
  93.             memcpy_fromfs (&tmp,(struct ipc_kludge *) ptr, 
  94.                        sizeof (tmp));
  95.             return sys_msgrcv (first, tmp.msgp, second, tmp.msgtyp,
  96.                          third);
  97.             }
  98.         case MSGGET:
  99.             return sys_msgget ((key_t) first, second);
  100.         case MSGCTL:
  101.             return sys_msgctl (first, second, 
  102.                         (struct msqid_ds *) ptr);
  103.         default:
  104.             return -EINVAL;
  105.         }
  106.     if (call <= SHMCTL) 
  107.         switch (call) {
  108.         case SHMAT: /* returning shmaddr > 2G will screw up */
  109.             return sys_shmat (first, (char *) ptr, second, 
  110.                             (ulong *) third);
  111.         case SHMDT: 
  112.             return sys_shmdt ((char *)ptr);
  113.         case SHMGET:
  114.             return sys_shmget (first, second, third);
  115.         case SHMCTL:
  116.             return sys_shmctl (first, second, 
  117.                         (struct shmid_ds *) ptr);
  118.         default:
  119.             return -EINVAL;
  120.         }
  121.     return -EINVAL;
  122. }
  123.  
  124. #else /* not CONFIG_SYSVIPC */
  125.  
  126. asmlinkage int sys_ipc (uint call, int first, int second, int third, void *ptr) 
  127. {
  128.     return -ENOSYS;
  129. }
  130.  
  131. int shm_fork (struct task_struct *p1, struct task_struct *p2)
  132. {
  133.     return 0;
  134. }
  135.  
  136. void sem_exit (void)
  137. {
  138.     return;
  139. }
  140.  
  141. void shm_exit (void)
  142. {
  143.     return;
  144. }
  145.  
  146. int shm_swap (int prio)
  147. {
  148.     return 0;
  149. }
  150.  
  151. void shm_no_page (unsigned long *ptent)
  152. {
  153.     return;
  154. }
  155.  
  156. #endif /* CONFIG_SYSVIPC */
  157.